<template>
  <div class="DatabaseTalents content-container">
    <div class="breadcrumb">数据库管理-人才管理</div>
    <div class="search_box">
      <!--筛选条件-->
      <div class="form">
        <el-form ref="query" style="font-size: 10px" v-model="query" label-width="92px" labelPosition="right">
          <el-row>
            <el-col :span="5">
              <el-form-item label="姓名：">
                <el-input v-model="query.name"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="身份证号：" >
                <el-input v-model="query.idCard"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="电话：">
                <el-input v-model="query.phone"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="邮箱：">
                <el-input v-model="query.email"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5">
              <el-form-item label="年龄：">
                <el-col :span="11">
                  <el-input v-model="query.frontAge" style="width: 100%;"></el-input>
                </el-col>
                <el-col class="line" :span="2">——</el-col>
                <el-col :span="11">
                  <el-input v-model="query.afterAge" style="width: 100%;"></el-input>
                </el-col>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="工作年限：">
                <el-col :span="11">
                  <el-input v-model="query.fronworkDay" style="width: 100%;"></el-input>
                </el-col>
                <el-col class="line" :span="2">——</el-col>
                <el-col :span="11">
                  <el-input v-model="query.afterworkDay" style="width: 100%;"></el-input>
                </el-col>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="所在地：">
                <el-input v-model="query.city"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="学历：">
                <DbSelector type="34" v-model="query.academic"/>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="性别：">
                <el-select style="width:100%;" v-model="query.sex">
                  <el-option label="全部" :value="undefined"></el-option>
                  <el-option label="男" value="0"></el-option>
                  <el-option label="女" value="1"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5">
              <el-form-item label="执业类型：">
<!--                <DbSelector type="13" v-model="query.license"/>-->
                <el-cascader
                        v-model="license"
                        :options="liOptions"
                        :props="{ expandTrigger: 'hover' }"
                        @change="handleChange"></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="职称：">
                <DbSelector type="15" v-model="query.title"/>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="审核状态：">
                <el-select style="width:100%;" v-model="query.state" placeholder="请选择活动区域">
                  <el-option label="全部" :value="undefined"></el-option>
                  <el-option label="未审核" value="0"></el-option>
                  <el-option label="已审核" value="1"></el-option>
                  <el-option label="异常" value="2"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="9" style="">
              <div class="search">
                <el-row :gutter="0" type="flex" justify="space-between">
                  <el-col :span="11" style="text-align: right" >
                    <a href="javascript:void(0)" v-if="false">
                      <img :src="delImg" alt="批量删除" @click="handleDelete">
                    </a>
                  </el-col>
                  <el-col :span="11" style="text-align: right" >
                    <el-button class="btn" @click="doshowTalent">查询</el-button>
                  </el-col>
                </el-row>
              </div>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </div>
    <!--表格-->
    <div class="opd" v-loading="loading">
      <el-table
        :data="table.data"
        header-row-class-name="tab_header"
        :cell-style="myCellStyle"
        style="width: 100%;font-size: 12px;"
        ref="table"
        height="100%"
        @selection-change="handleSelectionChange">
        <el-table-column type="selection" fixed min-width="25"></el-table-column>
        <el-table-column align="center" prop="id" label="ID" min-width="40"></el-table-column>
        <el-table-column align="center" prop="name" label="姓名" min-width="60"></el-table-column>
        <el-table-column align="center" prop="sex" label="性别" min-width="35">
          <template slot-scope="scope">{{scope.row.sex==0?'男':'女'}}</template>
        </el-table-column>
        <el-table-column align="center" prop="age"  label="年龄" min-width="35"></el-table-column>
        <el-table-column align="center" prop="idCard"  min-width="145" label="身份证号"></el-table-column>
        <el-table-column align="center" prop="license" min-width="155"  label="执业类型">
          <template slot-scope="scope">
            <div v-html="scope.row.license" ></div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="title" label="职称" min-width="70"></el-table-column>
        <el-table-column align="center" prop="academic" min-width="40" label="学历"></el-table-column>
        <el-table-column align="center" prop="workDay" min-width="50" label="工作年限"></el-table-column>
        <el-table-column align="center" prop="city"  label="所在地" min-width="80"></el-table-column>
        <el-table-column align="center" prop="phone"  label="电话"  min-width="100"></el-table-column>
        <el-table-column align="center" prop="email"  label="邮箱" min-width="135"></el-table-column>
        <el-table-column align="center" min-width="60" prop="state" label="状态">
          <template slot-scope="scope">
            <div class="ltabStatus" :style="scope.row.state==0?'color:#BDBDBD':(scope.row.state==1?'color:#409EFF':'color:red')">{{scope.row.state|stateFilter}}</div>
          </template>
        </el-table-column>
        <el-table-column align="center" min-width="40" prop="state" fixed="right" label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="doclick(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      style="text-align: right;margin-right: 40px"
      background
      @current-change="pageChange"
      :current-page.sync="query.currPageNo"
      :page-size="query.pageSize"
      layout="total,prev, pager, next"
      :total="table.total"
    ></el-pagination>
  </div>
</template>

<script>
import DbSelector from '@/components/selectors/DbSelector'
export default {
  name: 'DatabaseTalents',
  components: { DbSelector },
  data() {
    return {
      delImg:require("@/assets/imgs/delete.jpg"),
      loading: false,
      query: {
        currPageNo: 1,
        pageSize: 30,
        name: undefined,
        sex: undefined,
        fronworkDay: undefined,
        afterworkDay: undefined,
        phone: undefined,
        city: undefined,
        frontAge: undefined,
        afterAge: undefined,
        idCard: undefined,
        email: undefined,
        academic: undefined,
        license: undefined,
        state: undefined
      },
      table: {
        data: [],
        total: 1
      },
      rslicense:undefined,
      license:[],
      checkList: [],
      liOptions:[],
      msg: ''
    }
  },
  methods: {
    handleChange(value) {
      let temp = "";
      if(value != "0"){
        for(let index in value){
          if(index==0){
            temp = value[index];
          }else{
            temp += "-"+value[index];
          }
        }
        this.query.license = temp;
      }else{
        this.query.license = undefined;
      }
      console.log("info",this.query.license)
    },
    myCellStyle({row, column, rowIndex, columnIndex}){
       //console.log("column",column)
      return 'padding:0px;';
    },
    pageChange() {
      this.doshowTalent()
    },
    doshowTalent() {
      this.loading = true
      const params = {
        ...this.query
      }
      this.lAxios({
        method: 'post', //方法
        url: '/platform/getDatabaseTalent.do', //路径，基础路径在main.js里面配置
        params: this.$formatParams(params)
      }).then(res => {
          //成功的回调函数
          this.table.data = res.data.data.list;
          for(let i=0;i<this.table.data.length;i++){
            this.table.data[i].license = this.$b.lineFeedCustom(this.table.data[i].license,'<br>')
          }
          this.table.total = res.data.data.total
        })
        .finally(() => {
          this.loading = false
        })
    },
    handleEdit(index, row) {
      console.log(index, row)
      this.$router.push('/tableDetail')
    },
    handleDelete() {
      console.log(this.checkList)
      if (this.checkList.length > 0) {
        this.$confirm('确定删除吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this._doDelete()
        })
      }
    },
    _doDelete() {
      this.loading = true
      const params = {
        ids: this.checkList.join(',')
      }
      this.lAxios({
        method: 'post', //方法
        url: '/platform/deleteTalent.do', //路径，基础路径在main.js里面配置
        params: this.$formatParams(params)
      })
        .then(res => {
          //成功的回调函数
          if (res.data.status == 0) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.doshowTalent()
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
    handleSelectionChange(val) {
      this.checkList = val.map(item => {
        return item.id
      })
    },
    dosave() {},
    doclick(row) {
      this.$router.push({
        path: '/DatabaseTalents/details',
        query: { id: row.id }
      })
    }
  },
  created() {
    this.doshowTalent()
  },
  mounted(){
    this.lAxios({
      method: 'post', //方法
      url: '/platform/selectLicence.do', //路径，基础路径在main.js里面配置
      params: {id:13}
    }).then(res => {
       res = res.data;
       if(res.status==0){
            this.liOptions.push({label:"全部",value:0})
            for(let item of res.data){
                let bean = {};
                bean.label = item.licenseType;
                bean.value = item.licenseTypeId;
                bean.children = [];
                for(let child of item.licenseSonList){
                   let ch = {};
                   ch.label = child.licenseType;
                   ch.value = child.licenseTypeId;
                   bean.children.push(ch);
                }
               this.liOptions.push(bean)
               //console.log("item",item);
            }
       }
       //console.log("res",res);
    }).finally(() => {this.loading = false})
  },
  filters: {
    stateFilter(val) {
      let arr = ['未审核', '已审核', '异常']
      return arr[val]
    }
  }
}
</script>
<style lang="scss" >
.DatabaseTalents {
  width: 99%;
  /*height: 900px;*/
  padding-left: 1%;
  background-color: #f7f9fc;
  .breadcrumb {
    margin: 10px 0;
    font-size: 14px;
    color: #333;
  }
  .search_box {
    background-color: white;
    padding: 12px 50px;
    .form {
      margin-left: -20px;
      .el-form {
        .el-form-item__label {
          font-weight: 700;
          color: rgb(31, 46, 77);
          font-family: 'Arial Negreta', 'Arial Normal', 'Arial';
        }
        .el-input__inner{
          height: 30px;
        }
        .el-select .el-input .el-select__caret{
          display: none;
        }
      }
      .search {
        .btn {
          width: 140px;
          height: 40px;
          background-color: #37f;
          color: #fff;
        }
      }
    }
    .table {
      .tab_header {
        th {
          color: rgb(31, 46, 77);
          font-weight: 400;
          font-size: 14px;
          text-align: center;
          background-color: #e6e9f0;
        }
      }
    }
  }
  .opd{
    width: 100%;
    height:calc(100vh - 335px);
    overflow: auto;
  }
}
</style>
